<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>订单管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../../include/commonFile.jsp" %>
    <style type="text/css">
        .prod-logo {
            width: 80px;
            height: 80px;
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
            float: left;
            margin-right: 5px;
        }

        .layui-form-select dl {
            max-height: 250px !important;
        }

        .logistics-list {
            overflow-y: auto;
            max-height: 250px;
            border-top: 1px solid #e5e5e5;
        }

        .logistics-list li {
            text-align: left;
            line-height: 25px;
            margin-bottom: 10px;
        }

        .logistics-list li:first-child {
            color: orange;
        }

        .layui-table td, .layui-table th {
            padding: 10px !important;
        }

        .order-item {
            vertical-align: top;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/mall/order/list.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <input type="hidden" name="goodsId" value="${orderDetail.goodsId}"/>
                <input type="hidden" name="payStatus" value="${queryInput.payStatus}"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline">
                                <label class="search-form-lable">收货人姓名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="addressName" autocomplete="off" class="layui-input"
                                           value="${orderDetail.addressName}" placeholder="请输入收货人姓名">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">收货人手机</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="addressPhone" autocomplete="off" class="layui-input"
                                           value="${orderDetail.addressPhone}" placeholder="请输入收货人手机">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">商品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" autocomplete="off" class="layui-input"
                                           value="${orderDetail.title}" placeholder="请输入商品名称">
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item-inline">
                                <label class="search-form-lable" style="margin-right: 14px;">订单编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="orderId" autocomplete="off" class="layui-input"
                                           value="${orderDetail.orderId}" placeholder="请输入订单编号">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">分销商名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="distributorName" autocomplete="off" class="layui-input"
                                           value="${queryInput.distributorName}" placeholder="请输入分销商名称">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">交易单号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="transactionId" autocomplete="off" class="layui-input"
                                           value="${queryInput.transactionId}" placeholder="请输入交易单号">
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">订单类型</label>
                                <div class="check-btn-inner">
                                    <a id="all11" href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')"
                                    ${empty orderDetail.orderType or orderDetail.orderType ==1 ? 'class="active"' : ''}>实物订单</a>

                                    <a id="al11" href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${orderDetail.orderType == 2 ? 'class="active"' : ''}>积分订单</a>
                                    <input type="hidden" name="orderType" value="${orderDetail.orderType}"/>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">订单状态</label>
                                <div class="check-btn-inner">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),'','#myForm')" ${empty orderDetail.status ? 'class="active"' : ''}>全部</a>
                                    <c:forEach var="map" items="${statusMap}">
                                        <a href="javascript:void(0);"
                                           onclick="setTimeType($(this),'${map.key}','#myForm')" ${orderDetail.status == map.key ? 'class="active"' : ''}>${map.value}</a>
                                    </c:forEach>
                                    <input type="hidden" name="status" value="${orderDetail.status}"/>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">下单时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="my-act-list-content mt20">
                <div class="cl">
                    <table class="layui-table" lay-skin="line">
                        <colgroup>
                            <col>
                            <col width="10%">
                            <col width="8%">
                            <col width="8%">
                            <col width="15%">
                            <col width="10%">
                            <col width="9%">
                        </colgroup>
                        <thead>
                        <tr>
                            <td>商品</td>
                            <td align="center">单价/数量</td>
                            <td align="center">售后</td>
                            <td align="center">订单状态</td>
                            <td align="center">买家</td>
                            <td align="center">下单时间</td>
                            <td align="center">金额</td>
                        </tr>
                        </thead>
                        <c:if test="${page.totalCount == 0}">
                            <tr>
                                <td colspan="7" align="center">还没有相关数据</td>
                            </tr>
                        </c:if>
                    </table>
                    <c:forEach var="orderPay" items="${orderList}">
                        <table class="layui-table">
                            <colgroup>
                                <col>
                                <col width="10%">
                                <col width="8%">
                                <col width="8%">
                                <col width="15%">
                                <col width="10%">
                                <col width="9%">
                            </colgroup>
                            <tbody>
                            <tr>
                                <td colspan="7">
                                    <span class="mr10">订单编号：${orderPay.orderId}</span>
                                    <c:if test="${not empty orderPay.transactionId}">
                                        <span class="mr10">交易单号：${orderPay.transactionId}</span>
                                    </c:if>

                                    <span class="r">
                                            <a href="${ctx}/mall/order/getDetail.do?orderId=${orderPay.orderId}">查看详情</a>
                                            -
                                            <a href="javascript:void(0);"
                                               onclick="updateSellerRemarks('${orderPay.orderId}', this)">备注</a>
                                        </span>

                                </td>
                            </tr>
                            <c:set var="index" value="0"></c:set>
                            <c:forEach var="orderParent" items="${orderPay.childrens}" varStatus="j">
                                <tr>
                                    <td colspan="3">
                                        <c:if test="${empty orderParent.distributorId}">
                                            <span>所属者：${orderParent.distributorName}</span>
                                        </c:if>
                                        <c:if test="${not empty orderParent.distributorId}">
                                            <span class="mr15 red">分销者：${orderParent.distributorName}</span>
                                            <span class="red">利润：<fmt:formatNumber value="${orderParent.totalProfit}"
                                                                                   pattern="#.##"/></span>
                                        </c:if>
                                    </td>
                                    <c:if test="${index == 0}">
                                        <td class="order-item"
                                            rowspan="${orderPay.childCount + fn:length(orderPay.childrens)}"
                                            align="center">
                                            <div>
                                                <p>${orderPay.statusName}</p>
                                                <c:if test="${orderPay.status == 3}">
                                                    <p><a class="red shipment" href="javascript:void(0);"
                                                          onclick="doShopment('${orderPay.orderId}', this)">发货</a></p>
                                                </c:if>
                                                <c:if test="${orderPay.status == 4}">
                                                    <p><a class="red shipment"
                                                          href="javascript:searchShopment('${orderPay.orderId}')">修改物流</a>
                                                    </p>
                                                </c:if>
                                                <c:if test="${orderPay.logisticsStatus == 3 and orderPay.status != 7}">
                                                    <p><a class="red shipment"
                                                          href="javascript:receiveShipment('${orderPay.orderId}')">确认收货</a>
                                                    </p>
                                                </c:if>
                                            </div>
                                        </td>
                                        <td class="order-item"
                                            rowspan="${orderPay.childCount + fn:length(orderPay.childrens)}"
                                            align="center">
                                            <div class="member-cell"
                                                 onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${orderPay.memberId}','400px','470px')">
                                                <div class="member-logo" style="background-image: <c:if
                                                        test="${orderPay.logo != null}">url('${orderPay.logo}?imageMogr2/auto-orient/crop/126x126'),</c:if>url(${ctx}/image/def_user_logo.png)"></div>
                                                <div class="member-name ellipsis-1">
                                                    <a title="${orderPay.realname}"
                                                       href="javascript:void(0);">${orderPay.realname}</a>
                                                </div>
                                            </div>
                                            <div class="mt5">${orderPay.addressName}</div>
                                            <div class="mt5">${orderPay.addressPhone}</div>
                                        </td>
                                        <td class="order-item"
                                            rowspan="${orderPay.childCount + fn:length(orderPay.childrens)}"
                                            align="center">
                                            <div>
                                                <div><fmt:formatDate value="${orderPay.createDate}"
                                                                     pattern="yyyy-MM-dd"/></div>
                                                <div><fmt:formatDate value="${orderPay.createDate}"
                                                                     pattern="HH:mm:ss"/></div>
                                            </div>
                                        </td>
                                        <td class="order-item"
                                            rowspan="${orderPay.childCount + fn:length(orderPay.childrens)}"
                                            align="center">
                                            <div>
                                                <fmt:formatNumber value="${orderPay.price + orderPay.postage}"
                                                                  pattern="0.00"/>
                                            </div>
                                            <c:if test="${orderPay.postage > 0}">
                                                <div>（含运费：<fmt:formatNumber value="${orderPay.postage}" pattern="0.00"/>）</div>
                                            </c:if>
                                            <div>共${orderPay.quantity}件商品</div>
                                        </td>
                                    </c:if>
                                </tr>
                                <c:forEach var="orderChild" items="${orderParent.childrens}">
                                    <tr>
                                        <td>
                                            <div>
                                                <div class="prod-logo"
                                                     style="background-image: url('${orderChild.pic}')"></div>
                                                <div class="l">
                                                    <div class="ellipsis-2 mb10"
                                                         title="${orderChild.name}">${orderChild.name}</div>
                                                    <div class="ellipsis-1 mb5"
                                                         title="${orderChild.specValues}">${orderChild.specValues}</div>
                                                    <c:if test="${not empty orderChild.productNumber}">
                                                        <div>规格编码：<span class="red">${orderChild.productNumber}</span>
                                                        </div>
                                                    </c:if>
                                                </div>
                                                <div class="cl"></div>
                                            </div>
                                        </td>
                                        <td align="center">
                                            <div>
                                                <div><fmt:formatNumber value="${orderChild.price}"
                                                                       pattern="0.00"/></div>
                                                <div>(${orderChild.quantity}件)</div>
                                            </div>
                                        </td>
                                        <td align="center">
                                            <c:if test="${orderChild.status == 6}">
                                                <div class="hasApplyRefund">
                                                    <a class="red db"
                                                       href="javascript:checkRefund('${orderChild.id}', 1)">同意退款</a>
                                                    <a class="red db"
                                                       href="javascript:checkRefund('${orderChild.id}', 2)">拒绝退款</a>
                                                </div>
                                            </c:if>
                                            <c:if test="${orderChild.status == 9}">
                                                <p>退款成功</p>
                                            </c:if>
                                            <c:if test="${orderChild.status == 5}">
                                                <p>退款拒绝</p>
                                                <a class="red db" href="javascript:checkRefund('${orderChild.id}', 1)">同意退款</a>
                                            </c:if>
                                        </td>
                                    </tr>
                                    <c:set var="index" value="${index + 1}"></c:set>
                                </c:forEach>
                            </c:forEach>
                            <tr ${empty orderPay.buyerRemarks ? 'style="display:none"' : ''}>
                                <td colspan="7">
                                    <div>买家备注：<span>${orderPay.buyerRemarks}</span></div>
                                </td>
                            </tr>
                            <tr ${empty orderPay.sellerRemarks ? 'style="display:none"' : ''}>
                                <td colspan="7">
                                    <div>卖家备注：<span class="seller-remarks">${orderPay.sellerRemarks}</span></div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </c:forEach>
                </div>
                <div id="page_content" class="page-container"></div>
            </div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
    <div id="selectOrderDetail" class="p10"></div>
    <form id="searchShipment" class="p10 layui-form"></form>
    <jsp:include page="includeSellerRemarks.jsp"/>
</div>
<jsp:include page="includeShipment.jsp"/>
<jsp:include page="includeSearchShipment.jsp"/>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">

    <%--showActive('${input.createStart}', '${input.createEnd}', '#timeType');--%>

    var form, laytpl, laydate = null;

    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        $("#btnExport").click(function () {
            layer.confirm('确认要导出Excel吗?', {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var url = "${ctx}/mall/order/export.do?actId=${activity.id}";
                var action = $("#myForm").attr("action");
                $("#myForm").attr("action", url);
                $("#myForm").submit();
                $("#myForm").attr("action", action);
                top.layer.close(index);
            });
        });

        layui.use(['form', 'laytpl', 'laydate'], function () {
            form = layui.form, laytpl = layui.laytpl, laydate = layui.laydate;

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);

            //监听提交
            form.on('submit(infoForm)', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#infoForm").attr("action");
                    $.post(action, $('#infoForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                submitFunction('#myForm');
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    })
                });
                return false;
            });

            form.on('checkbox(chk)', function (data) {
                var length = $("#selectOrderDetail tbody").find(":checked").length;
                $("#selectNum").text(length);
            });
        });
    });

    function openDialog(title, content, width, height, cb, target) {
        var index = layer.open({
            type: 1,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: $(content),
            btn: ['确定', '取消'],
            yes: function () {
                cb(index);
            }
        });
    }

    // 退款审核
    function checkRefund(orderDetailId, status) {
        var msg = "";
        if (status == 1) {
            msg = "确认同意退款？";
        } else if (status == 2) {
            msg = "确认拒绝退款？";
        }
        layer.confirm(msg, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/mall/order/checkRefund.do", {
                "orderDetailId": orderDetailId,
                "status": status
            }, function (data) {
                layer.close(loadIndex);
                if (data.success) {
                    util.layerMsgSuccess("操作成功！", function () {
                        window.location.reload();
                    });
                } else {
                    util.layerMsgError(data.description)
                }
                top.layer.close(index);
            });
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '订单管理',
            curr: true
        }],
        info: '<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>'
    });
</script>
</body>
</html>